package guestbook;

import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import org.joda.time.DateTimeZone;
import org.joda.time.LocalDateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import com.google.appengine.api.datastore.Key;

@PersistenceCapable
public class Message {
	@PrimaryKey
	@Persistent( valueStrategy = IdGeneratorStrategy.IDENTITY )
	private Key key;
	
	@Persistent
	private String username;
	@Persistent
	private String usermessage;
	@Persistent
	private Date messageDate;

	public Message( String username, String usermessage, Date messageDate ) {
		setUsername( username );
		setUsermessage( usermessage );
		setMessageDate( messageDate );
	}

	public Key getKey() {
		return key;
	}
	public void setKey( Key key ) {
		this.key = key;
	}

	public String getUsername() {
		return username;
	}
	public void setUsername( String username ) {
		this.username = username;
	}

	public String getUsermessage() {
		return usermessage;
	}
	public void setUsermessage( String usermessage ) {
		this.usermessage = usermessage;
	}

	public Date getMessageDate() {
		return messageDate;
	}
	public void setMessageDate( Date messageDate ) {
		this.messageDate = messageDate;
	}

	public String getFormattedDate() {
		LocalDateTime ldt = new LocalDateTime( messageDate, DateTimeZone.forID( "America/Sao_Paulo" ) );
		DateTimeFormatter dtf = DateTimeFormat.forPattern( "dd/MM/yyyy 'as' HH:mm:ss" );
		
		return dtf.print( ldt );
	}
	
}